<?php
namespace Home\Controller;

use Think\Controller;

class WeichatController extends Controller{
    protected $weiChat;
    public function _initialize(){
        $this->weiChat = new \Org\Weichat\Weichat(C('WX_TOKEN'),C('APPID'),C('APPSECRET'));
    }
    public function valid(){
        $data = I('get.');
        $this->weiChat->valid($data);
        // $this->weiChat->replyText('欢迎来到野兽家园');
    }

    public function setMenu(){
        $baseurl = urlencode('http://202.5.22.160/');
        $shopurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".C('APPID')."&redirect_uri=".$baseurl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
        $data = array(
            'button' => array(
                array(
                    'type'=>'click',
                    'name'=>'点我啊',
                    'key'=>'您好',
                    ),
                array(
                    'name'=>'新安商城',
                    'sub_button'=>array(
                        array(
                            'type'=>'view',
                            'name'=>'我要买',
                            'url'=>$shopurl,
                            ),
                        array(
                            'type'=>'view',
                            'name'=>'看商品',
                            'url'=>$shopurl,
                            ),
                        
                        ),
                    )
            ),
        );
        $this->weiChat->setMenu($data);
    }
}